import request from "@/utils/request";

export function fetchList(query) {
  return request({
    url: "admin/role/index?page=1&page_size=10&sort_field=id&sort_order=desc&name=&code=",
    method: "get",
    params: query,
  });
}

export function fetchUser(id) {
  return request({
    url: `/users/${id}`,
    method: "get",
  });
}

export function createUser(data) {
  return request({
    url: "/users",
    method: "post",
    data,
  });
}

export function updateUser(id, data) {
  return request({
    url: `/users/${id}`,
    method: "put",
    data,
  });
}

export function deleteUser(id) {
  return request({
    url: `/users/${id}`,
    method: "delete",
  });
}

export const getAdministratorList = (params) => {
  return request({
    url: "/api/admin/sysUser/list",
    method: "post",
    data: { ...params },
  });
};
export const addAdministratorItem = (data) => {
  return request({
    url: "/api/admin/sysUser/add",
    method: "post",
    data: data,
  });
};

export const editAdministratorItem = (data) => {
  return request({
    url: "/api/admin/sysUser/update",
    method: "put",
    data: data,
  });
};
export const updateUserStatus = (data) => {
  return request({
    url: `/api/admin/sysUser/updateStatus/${data.id}/${data.userStatus}`,
    method: "put",
  });
};

export const updateUserPassword = (data) => {
  return request({
    url: `/api/admin/sysUser/updatePassword`,
    method: "put",
    data: data,
  });
};

export const assignUserRoles = (data) => {
  return request({
    url: "/api/admin/role/assign",
    method: "post",
    data: data,
  });
};


export const getRoleListByUserId = (userId) => {
  return request({
    url: `/api/admin/sysUser/roleListByUserId/${userId}`,
    method: "get",
  });
};
